package com.easy.dfcapi.service.impl;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.common.util.Utility;
import com.easy.dfcapi.entity.ApiUser;
import com.easy.dfcapi.mapper.ApiBuyerMapper;
import com.easy.dfcapi.mapper.ApiStoreMapper;
import com.easy.dfcapi.mapper.ApiUserMapper;
import com.easy.dfcapi.res.*;
import com.easy.dfcapi.service.ApiBuyerService;
import com.easy.dfcapi.utils.ApiSessionUser;
import com.easy.dfcapi.utils.ServletHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * Created by VULCANTSeries on 2017/5/10.
 */
@Service
@Transactional(readOnly = true)
public class ApiBuyerServiceImpl implements ApiBuyerService {

    @Autowired
    private ApiUserMapper userMapper;

    @Autowired
    private ApiStoreMapper storeMapper;

    @Autowired
    private ApiBuyerMapper buyerMapper;

    @Override
    public Result HomePage() throws Exception{
        Integer askSize = 5; //风车话题前五
        Integer productSize = 4;//天天焕新 前4
        Integer factorySize = 4;//好厂推荐 前4
        Integer niceFactoryProductSize = 10;
        Result rt = new Result();
        try{

            List<Map<String,Object>> bannerList = buyerMapper.getHomeBanner();////顶部轮播
            List<Map<String,Object>> askOtherList = buyerMapper.getNewList(askSize);//风车话题前五
            List<Map<String,Object>> newProductList = buyerMapper.getNewProductList(productSize);//天天焕新
            List<Map<String,Object>> niceFactoryList = buyerMapper.getNiceFactoryList(factorySize);//好厂推荐，订单最多的店铺

            List<Map<String,Object>> berserkProductList = buyerMapper.getBerserkProductList(factorySize); //疯抢

            List<Map<String,Object>> liveList =  buyerMapper.getNowLiveList(niceFactoryProductSize);//首页风车直播

            //List<Map<String,Object>> nicebrandList =  buyerMapper.getNiceBrandList(niceFactoryProductSize);//首页精选品牌
            //List<Map<String,Object>> niceFactoryTodayList = buyerMapper.getNiceFactoryTodayList(niceFactoryProductSize); //首页每日好厂

            List<Map<String,Object>> nicebrandList =  buyerMapper.getBrandProSaleMax();//首页精选品牌
            List<Map<String,Object>> niceFactoryTodayList = buyerMapper.getFactoryProSaleMax(); //首页每日好厂


            Map<String,Object> map = new HashMap<String,Object>();
            if(bannerList == null)bannerList = new ArrayList();
            if(liveList == null)liveList = new ArrayList();
            if(askOtherList == null)askOtherList = new ArrayList();
            if(newProductList == null)newProductList = new ArrayList();
            if(niceFactoryList == null)niceFactoryList = new ArrayList();
            if(nicebrandList == null)nicebrandList = new ArrayList();

            map.put("banner",bannerList);
            map.put("askOther",askOtherList);
            map.put("newProduct",newProductList);
            map.put("berserkProduct",berserkProductList);
            map.put("niceFactory",niceFactoryList);
            map.put("liveList",liveList);
            map.put("niceBrand",nicebrandList);
            map.put("niceFactoryToday",niceFactoryTodayList);
            rt.setStatus(EnumConfig.S_CODE.OK);

            rt.setData(map);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;

    }

    /**
     * 首页精选宝贝
     *  按销量分页获取
     * @param response
     * @return
     */
    @Override
    public Result NiceProduct(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);

            List niceProductList = buyerMapper.getNiceProduct(data.getPageIndex(),data.getPageSize()); //首页每日好厂
            if(niceProductList == null)niceProductList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(niceProductList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }
        return rt;
    }

    /**
     * 品牌馆/潮流馆-本周最大牌
     *
     * @param response
     * @return
     */
    @Override
    public Result BestOnWeek(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.BestOnWeek(data.getType()); //品牌馆/潮流馆-本周最大牌
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 品牌馆/潮流馆-今日我大牌
     *
     * @param response
     * @return
     */
    @Override
    public Result BestToday(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List factoryList = buyerMapper.BestToday(data.getPageIndex(), data.getPageSize(), data.getType()); //品牌馆/潮流馆-今日我大牌
            if (factoryList == null) factoryList = new ArrayList();
            List ls = new ArrayList();
            for (int i = 0; i < factoryList.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
                int factoryId = (Integer) map.get("factoryId");
                List<Map<String, Object>> list = buyerMapper.getNiceProductByFactoryId(factoryId);
                map.put("product", list);
                ls.add(map);
            }
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(ls);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }
        return rt;
    }
    /**
     * 品牌馆/潮流馆-今日我大牌更多。
     *
     * @param response
     * @return
     */
    @Override
    public Result BestTodayMore(Response<BuyerUserRes> response) {
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List factoryList = buyerMapper.BestTodayMore(data.getPageIndex(), data.getPageSize(), data.getType()); //品牌馆/潮流馆-今日我大牌更多。
            if (factoryList == null) factoryList = new ArrayList();
            List ls = new ArrayList();
            for (int i = 0; i < factoryList.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
                int factoryId = (Integer) map.get("factoryId");
                List<Map<String, Object>> list = buyerMapper.getNiceProductByFactoryId(factoryId);
                map.put("product", list);
                ls.add(map);
            }
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(ls);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 品牌馆/潮流馆-今日我最爆
     *
     * @param response
     * @return
     */
    @Override
    public Result BestProductToday(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.BestProductToday(data.getPageIndex(), data.getPageSize(), data.getType()); //品牌馆/潮流馆-今日我最爆
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 童品汇首页-商家列表
     *
     * @param response
     * @return
     */
    @Override
    public Result TPFactoryList(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            List factoryList = buyerMapper.TPFactoryList(data.getPageIndex(),data.getPageSize()); //童品汇首页-商家列表
            if (factoryList == null) factoryList = new ArrayList();
            List ls = new ArrayList();
            for (int i = 0; i < factoryList.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
                int factoryId = (Integer) map.get("factoryId");
                List<Map<String, Object>> list = buyerMapper.getNiceProductByFactoryId(factoryId);
                map.put("product", list);
                ls.add(map);
            }
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(ls);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 童品汇首页-商品列表
     *
     * @param response
     * @return
     */
    @Override
    public Result TPBestProduct(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.TPBestProduct(data.getAgeGroup(), data.getPageIndex(),data.getPageSize()); //童品汇首页-商品列表
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 尾品汇首页-商家列表
     *
     * @param response
     * @return
     */
    @Override
    public Result WPFactoryList(Response<BuyerUserRes> response) throws Exception {
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List factoryList = buyerMapper.WPFactoryList(data.getPageIndex(),data.getPageSize()); //尾品汇首页-商家列表
            if (factoryList == null) factoryList = new ArrayList();
            List ls = new ArrayList();
            for (int i = 0; i < factoryList.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
                int factoryId = (Integer) map.get("factoryId");
                List<Map<String, Object>> list = buyerMapper.getNiceProductByFactoryId(factoryId);
                map.put("product", list);
                ls.add(map);
            }
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(ls);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 尾品汇首页-商品列表
     *
     * @param response
     * @return
     */
    @Override
    public Result WPBestProduct(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.WPBestProduct(data.getAgeGroup(), data.getPageIndex(),data.getPageSize()); //童品汇首页-商品列表
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }


    /**
     * 尾品汇首页-今日抢购、明日预告
     *
     * @param response
     * @return
     */
    @Override
    public Result WPProduct(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.WPProduct(data.getAgeGroup(), data.getPageIndex(),data.getPageSize(), data.getDay()); //尾品汇首页-今日抢购、明日预告
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 天天焕新
     *
     * @param response
     * @return
     */
    @Override
    public Result DayDayProduct(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List productList = buyerMapper.DayDayProduct(data.getPageIndex(),data.getPageSize()); //天天焕新
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 好厂推荐
     *
     * @param response
     * @return
     */
    @Override
    public Result NiceFactory(Response<BuyerUserRes> response)  throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List factoryList = buyerMapper.NiceFactory(data.getPageIndex(),data.getPageSize()); //尾品汇首页-商家列表
            if (factoryList == null) factoryList = new ArrayList();
            List ls = new ArrayList();
            for (int i = 0; i < factoryList.size(); i++) {
                Map<String, Object> map = (Map<String, Object>) factoryList.get(i);
                int factoryId = (Integer) map.get("factoryId");
                List<Map<String, Object>> list = buyerMapper.getNiceProductByFactoryId(factoryId);
                map.put("product", list);
                ls.add(map);
            }
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(ls);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    @Override
    public Result Banner(Response<BuyerUserRes> response) throws Exception{
        Result rt = new Result();
        try{
            BuyerUserRes data = response.getData(BuyerUserRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            List<Map<String, Object>> bannerList = buyerMapper.getMoreBanner(data.getType());////顶部轮播
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(bannerList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 天天特价首页
     *
     * @param response
     * @return
     */
    @Override
    public Result DaySpecialOffer(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Map<String, Object> map = new HashMap();
            Date now = new Date();
            if (data.getPageSize() < 4) data.setPageSize(4) ;
            List todayProductList = buyerMapper.DaySpecialOffer(data.getAgeGroup(), data.getPageSize(), now); //尾品汇首页-商家列表
            if (todayProductList == null) todayProductList = new ArrayList();
            List tomorrowProductList = buyerMapper.DaySpecialOffer(data.getAgeGroup(), data.getPageSize(), Utility.getDayAfter(now, 1)); //尾品汇首页-商家列表
            if (tomorrowProductList == null) tomorrowProductList = new ArrayList();
            map.put("todayList", todayProductList);
            map.put("tomorrowList", tomorrowProductList);
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(map);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 天天特价更多
     *
     * @param response
     * @return
     */
    @Override
    public Result DaySpecialOfferMore(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Map<String, Object> map = new HashMap();
            Date now = new Date();
            List productList = buyerMapper.DaySpecialOfferMore(data); //尾品汇首页-商家列表
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 订货会首页
     *
     * @param response
     * @return
     */
    @Override
    public Result OrderMeeting(Response<ActivityEnrollQueryRes> response)  throws Exception{
        Result rt = new Result();
        try{
            ActivityEnrollQueryRes data = response.getData(ActivityEnrollQueryRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Map<String, Object> map = new HashMap();
            Date now = new Date();
            List productList = buyerMapper.OrderMeeting(data); //订货会首页
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 订货会详情
     *
     * @param response
     * @return
     */
    @Override
    public Result OrderMeetingDetail(Response<ActivityEnrollQueryRes> response)  throws Exception{
        Result rt = new Result();
        try{
            ActivityEnrollQueryRes data = response.getData(ActivityEnrollQueryRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Map<String,Object> map = new HashMap();
            Date now = new Date();
            Map<String,Object> productMap = buyerMapper.OrderMeetingDetail(data); //订货会详情
            if(productMap == null)productMap = new HashMap<String,Object>();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productMap);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 订货会详情商品
     *
     * @param response
     * @return
     */
    @Override
    public Result OrderMeetingDetailProduct(Response<ActivityEnrollQueryRes> response)  throws Exception{
        Result rt = new Result();
        try{
            ActivityEnrollQueryRes data = response.getData(ActivityEnrollQueryRes.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            Map<String,Object> map = new HashMap();

            Date now = new Date();
            List productList = buyerMapper.OrderMeetingDetailProduct(data); //订货会详情
            if(productList == null)productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 聚爆款首页
     *
     * @param response
     * @return
     */
    @Override
    public Result ImplosionList(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Map<String, Object> map = new HashMap();
            Date now = new Date();
            List productList = buyerMapper.ImplosionList(data); //聚爆款首页
            if (productList == null) productList = new ArrayList();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 跳尾货场次
     *
     * @param response
     * @return
     */
    @Override
    public Result JumpTailTime(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Date now = new Date();
            List<Map<String,Object>> timeList = buyerMapper.getJumpTailTime();
            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(timeList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }

    /**
     * 跳尾货场次列表
     *
     * @param response
     * @return
     */
    @Override
    public Result JumpTailList(Response<Product> response)  throws Exception{
        Result rt = new Result();
        try{
            Product data = response.getData(Product.class);
            ApiSessionUser sessionUser = ServletHelper.getSessionUserByToken(response.getToken());
            if(sessionUser == null){
                rt.setStatus(EnumConfig.S_CODE.NOT_USER);
                return rt;
            }

            ApiUser user = userMapper.getByUserId(sessionUser.getUserId());
            if(user==null){
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }

            Date now = new Date();
            //List<Map<String, Object>> ls = new ArrayList<Map<String, Object>>();
            //List<Map<String,Object>> timeList = buyerMapper.getJumpTailTime();
            //for (int i = 0; i < timeList.size(); i++) {
            //    Map tmap = (Map)timeList.get(i);
            //    Integer ltime = (Integer)tmap.get("ltime");
            //    Map<String, Object> map = new HashMap<String, Object>();
            //    map.put("ltime", ltime);
            //    para.setDay(ltime);
            //    List productList = buyerMapper.getJumpTailList(para); //订货会详情
            //    if (productList == null) productList = new ArrayList();
            //    map.put("product", productList);
            //    ls.add(map);
            //}
            List<Map<String,Object>> productList = buyerMapper.getJumpTailList(data); //订货会详情
            if (productList == null) productList = new ArrayList();

            rt.setStatus(EnumConfig.S_CODE.OK);
            rt.setData(productList);
        }catch(Exception ex){
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            throw ex;
        }

        return rt;
    }


}
